﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace tsgl
{
    class penaltyClass
    {
        public static DataTable getPenaltyBaseInfo(string strField)
        {
            return bookDbClass.ExecuteDataTable("select * from 罚款类型 where 罚款种类='"+strField+"'");
        }

        public static string getPenaltyBase(string strValue)
        {
            string commstr = "select 罚款基数 from 罚款类型 where 罚款原因='"+strValue+"'";
            DataTable dt = bookDbClass.ExecuteDataTable(commstr);
            return dt.Rows[0]["罚款基数"].ToString();
        }

        public static float getMultiple(string strValue)
        {
            string commstr = "select 罚款倍率 from 罚款类型 where 罚款原因='"+strValue+"'";
            DataTable dt = bookDbClass.ExecuteDataTable(commstr);
            return float.Parse(dt.Rows[0]["罚款倍率"].ToString());
        }

        public static int foreigftReduce(string borrowerId, float penaltyMoney)
        {
            string strsql = "update 借阅者信息 set 押金剩余=押金剩余-"+penaltyMoney+" where 借阅者编号='"+borrowerId+"'";
            return bookDbClass.ExecuteNonQurey(strsql);
        }

        /*
        public void penaltyRecordAdd(string borrwoerId,string borrowerName,string bookCode,string bookName,string penaltyCause,string penaltyWay,float penaltyMoney,DateTime penaltyDate,string operatorName,string tableName)
        {
                string strInsertComm;
                if (tableName == "罚款信息")
                {
                    try
                    {
                        strInsertComm = "insert into 罚款信息(借阅者编号,借阅者姓名,图书条码,图书名称,罚款原因,罚款方法,罚款金额,罚款日期,操作员) values(@a,@b,@c,@d,@e,@f,@g,@h,@i)";
                        //strInsertComm = "insert into 罚款信息(借阅者编号,借阅者姓名,图书条码,图书名称,罚款原因,罚款方法,罚款金额,罚款日期,操作员) values('"+borrwoerId+"','"+borrowerName+"','"+bookCode+"','"+bookName+"','"+penaltyCause+"','"+penaltyWay+"','"+penaltyMoney+"','"+penaltyDate+"','"+operatorName+"','"+tableName+"')";
                        bookDbClass.ExecuteDataTable(strInsertComm, new SqlParameter("a", borrwoerId), new SqlParameter("b", borrowerName), new SqlParameter("c", bookCode), new SqlParameter("d", bookName), new SqlParameter("e", penaltyCause), new SqlParameter("f", penaltyWay), new SqlParameter("g", penaltyDate), new SqlParameter("h", operatorName), new SqlParameter("i", tableName));
                        //return bookDbClass.ExecuteDataTable(strInsertComm);
                        //return true;
                    }
                    catch (Exception)
                    {
                        //return false;
                    }
                }
                if (tableName == "待罚款信息")
                {
                    try
                    {
                        strInsertComm = "insert into 待罚款信息(借阅者编号,借阅者姓名,图书条码,图书名称,罚款原因,罚款方法,罚款金额,罚款日期,操作员) values(@a,@b,@c,@d,@e,@f,@g,@h,@i)";
                        //strInsertComm = "insert into 罚款信息(借阅者编号,借阅者姓名,图书条码,图书名称,罚款原因,罚款方法,罚款金额,罚款日期,操作员) values('" + borrwoerId + "','" + borrowerName + "','" + bookCode + "','" + bookName + "','" + penaltyCause + "','" + penaltyWay + "','" + penaltyMoney + "','" + penaltyDate + "','" + operatorName + "','" + tableName + "')";
                        bookDbClass.ExecuteDataTable(strInsertComm, new SqlParameter("a", borrwoerId), new SqlParameter("b", borrowerName), new SqlParameter("c", bookCode), new SqlParameter("d", bookName), new SqlParameter("e", penaltyCause), new SqlParameter("f", penaltyWay), new SqlParameter("g", penaltyDate), new SqlParameter("h", operatorName), new SqlParameter("i", tableName));
                        //return bookDbClass.ExecuteDataTable(strInsertComm);
                        //return true;
                    }
                    catch (Exception)
                    {
                        //return false;
                    }
                }
        }*/

        public static Boolean penaltyStayDelete(string borrowerId, string bookCode)
        {
            try
            {
                string strsql = "delete from 待罚款信息 where 借阅者编号='" + borrowerId + "' and 图书条码='" + bookCode + "'";
                bookDbClass.ExecuteNonQurey(strsql);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
